package com.myx.typhoon.web.intercepter;

import org.springframework.security.core.Authentication;
import org.springframework.ui.ModelMap;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.context.request.WebRequestInterceptor;

import com.myx.typhoon.web.context.WebContext;
import com.myx.typhoon.web.security.SecurityUtil;

/**  
 * @author myx
 * @createTime 2016年1月6日 上午11:14:06  
 * 
 */
public class CommonInterceptor implements WebRequestInterceptor {

	@Override
	public void preHandle(WebRequest request) throws Exception {
		//设置唯一id，作用于单次请求
		//request.setAttribute("globalid", WebContext.getGolbalId(), WebRequest.SCOPE_REQUEST);
		//Authentication auth = SecurityUtils.getAuth();
		request.setAttribute("signin",false, WebRequest.SCOPE_REQUEST);
		if(SecurityUtil.getCurrentUser() != null) {
			request.setAttribute("username", SecurityUtil.getCurrentUser().getUsername(), WebRequest.SCOPE_SESSION);
			request.setAttribute("signin",true, WebRequest.SCOPE_REQUEST);
		}
	}

	@Override
	public void postHandle(WebRequest request, ModelMap model) throws Exception {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void afterCompletion(WebRequest request, Exception ex)
			throws Exception {
		// TODO Auto-generated method stub
		
	}

}
